package com.itheima.controller;

import com.itheima.service.SoundService;
import com.tanhua.model.vo.SoundVo;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author zwy
 */
@RestController
@RequestMapping("/peachblossom")
public class SoundController {

    @Autowired
    private SoundService soundService;


    /**
     * 发送语音
     */
    @PostMapping
    public ResponseEntity<Void> saveSound(@RequestParam(value = "soundFile", required = false) MultipartFile[] soundFile) {
        String id = soundService.saveSound(soundFile);
        if (StringUtils.isNotEmpty(id)) {
            return ResponseEntity.ok(null);
        }
        return ResponseEntity.ok(null);
    }

    /**
     * 接收语音
     */
    @GetMapping
    public ResponseEntity<SoundVo> receiveSound() {
        SoundVo soundVo = soundService.receiveSound();
        return ResponseEntity.ok(soundVo);
    }


}
